package com.yfker.td;

import com.tinder.scarlet.Lifecycle;
import com.tinder.scarlet.Scarlet;
import com.tinder.scarlet.WebSocket;
import com.tinder.scarlet.retry.BackoffStrategy;
import com.tinder.scarlet.streamadapter.rxjava2.RxJava2StreamAdapterFactory;
import com.yfker.td.factory.GsonMessageAdapter;

public class TDSocketManager {
    private static final int RETRY_CONNECT_TIME = 20000;
    private static volatile TDSocketManager INSTANCE;

    private TDSocketManager() {
    }

    public static TDSocketManager getInstance() {
        if (INSTANCE == null) {
            Class var0 = TDSocketManager.class;
            synchronized (TDSocketManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new TDSocketManager();
                }
            }
        }

        return INSTANCE;
    }

    public Scarlet config(WebSocket.Factory factory, Lifecycle lifecycle, BackoffStrategy strategy) {
        return (new Scarlet.Builder()).lifecycle(lifecycle)
                .backoffStrategy(strategy)
                .addStreamAdapterFactory(new RxJava2StreamAdapterFactory())
                .addMessageAdapterFactory(new GsonMessageAdapter.Factory()).webSocketFactory(factory).build();
    }
}
